"use strict";

const Service = require("egg").Service;
const UUID = require("uuid");

class UserService extends Service {
  /**
   * @查询用户
   */
  async getUserList() {
    const { ctx } = this;
    try {
      const result = await app.mysql.select("egg");
      return result;
    } catch (error) {
      // 记录错误日志
      this.logger.error(
        `${ctx.helper.zhDate()} : user服务创建时发生错误 --- ${error}`
      );
      const errorBody = {
        code: 500,
        data: null,
        message: "参数有毒:" + error,
      };
      return errorBody;
    }
  }

  /**
   * @创建用户
   */
  async createUser() {
    const { ctx } = this;
    try {
      const id = UUID.v1();
      const class_id = null;
      //   return await ctx.model.User.create({ id, class_id, ...ctx.request.body });
      this.logger.info({
        id,
        class_id,
        ...ctx.request.body,
      });
    } catch (error) {
      // 记录错误日志
      this.logger.error(
        `${ctx.helper.zhDate()} : user服务创建时发生错误 --- ${error}`
      );
      const errorBody = {
        code: 500,
        data: null,
        message: "参数有毒:" + error,
      };
      return errorBody;
    }
  }
}

module.exports = UserService;
